import { reqCategory1List } from "@/api/goods/attr";
import { ICateOne } from "@/types/attr";
import { createSlice } from "@reduxjs/toolkit";

// 创建切片对象
const cateSlice=createSlice({
name:'categoryone',
initialState:{
    value:[] as ICateOne[]
},
reducers:{
    // 添加一级分类的数据
    add:(state,{payload})=>{
        state.value=payload
    },
    // 重置
    clear:function(state,action){
        state.value=[]
    }
}
})

// 导出定义的方法
export const {add,clear}=cateSlice.actions

// 设置请求一级分类的数据
export const categoryoneList= ()=>{
    return async(dispatch:any)=>{
        const res= await  reqCategory1List()
        if(res.code===200){            
       dispatch(add(res.data))       
        }
    }
}


export default cateSlice.reducer